package rungekutta;

import java.util.Locale;

public class Main {

    public static void printHelp() {
        System.out.println("Usage:");
        System.out.println("java -jar Runge-Kutta.jar -i inputFile [-o order] [-s step] [-e accuracy] [-a autoStep_accuracy] [-r]");
        System.exit(0);
    }

    public static void main(String[] args) {
        try {
            Locale.setDefault(Locale.UK);
            String inputFile = "";
            int order = 4;
            double step = 0;
            double eps = 1e-10;
            double autoEps = 1e-1;
            boolean result = false;
            if (args.length == 0) {
                printHelp();
            }
            int i = 0;
            String param;
            while (i < args.length) {
                if (args[i].charAt(0) == '-') {
                    if (args[i].equals("-r")) {
                        result = true;
                        i++;
                        continue;
                    }
                    if (i == args.length - 1) {
                        printHelp();
                    }
                    param = args[i].substring(1);
                    switch (param.charAt(0)) {
                        case 'i':
                            inputFile = args[i + 1];
                            i++;
                            break;
                        case 'o':
                            order = Integer.parseInt(args[i + 1]);
                            i++;
                            break;
                        case 's':
                            step = Double.parseDouble(args[i + 1]);
                            i++;
                            break;
                        case 'e':
                            eps = Double.parseDouble(args[i + 1]);
                            i++;
                            break;
                        case 'a':
                            autoEps = Double.parseDouble(args[i + 1]);
                            i++;
                            break;
                        default:
                            printHelp();
                    }
                } else {
                    printHelp();
                }
                i++;
            }
            if (inputFile.equals("")) {
                printHelp();
            }
            Problem rk = new Problem(inputFile, order, step, eps, autoEps, result);
        } catch (Exception e) {
            printHelp();
        }
    }

}
